﻿using System;
using System.Collections.Generic;
using System.Text;

namespace BEGDC.MIS.Office.Excel
{
    /// <summary>
    /// Regular sample
    /// http://regexlib.com/DisplayPatterns.aspx?cattabindex=2&categoryId=3
    /// </summary>
    class Regular: IValidation
    {
        public bool Validate( Element element, string value)
        {

            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(element.Rule);

            bool ret = regex.IsMatch(value);

            if (!ret)
               throw new BEGDC.Utility.ExceptionManagement.GDCException("01.0099", string.Format(@"数据验证错误. 错误的位置为:{0}, 举例:{2}.\n\nData validate error. Position:{0}, Sample:{2}", element.Position, element.Rule, element.Sample));
                //throw new BEGDC.Utility.ExceptionManagement.GDCException("01.0099", string.Format( "数据验证错误. 错误的位置为:{0}, 数据验证表达式为:{1}, 举例:{2}", element.Position, element.Rule, element.Sample));

            return ret;
        }
    }
}
